package cn.iocoder.yudao.framework.weixin;


import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.BaseWxCpServiceImpl;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpTpDepart;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
import me.chanjar.weixin.cp.config.impl.AbstractWxCpInRedisConfigImpl;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceApacheHttpClientImpl;
import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceImpl;

import javax.annotation.Resource;
import java.util.List;


public class WxCpServiceTest {
    /**
     * corpid:ww00b36ed5acf38dc9
     * AgentId：1000088
     * Secret：Q3wRLD9KRPMYAFpQ7EChakoRe5lWE9lt45kjfRN3sMk
     * @param args
     * @throws WxErrorException
     *模板ID：dk83899bb2c060ce44
     * 模板Secret：iK3sD1n5ovlRTDOl424mu5uGKO_VgXS5oa7V2Yf9UMA
     * 请求地址： https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=1000088&corpsecret=Q3wRLD9KRPMYAFpQ7EChakoRe5lWE9lt45kjfRN3sMk
     */
    static Integer agentId=1000088;

    static String providerSecret="gFjBpLXZcwSYCdI6hq2bMxBnlw-v1Xkk0WbTJJVhAAZ1soHfXgF0Owpi-yKl9AgD";


    //模板id  模板密钥
    static String secret="iK3sD1n5ovlRTDOl424mu5uGKO_VgXS5oa7V2Yf9UMA";
    static String corpid="dk83899bb2c060ce44";
    public static void main(String[] args) throws WxErrorException {

        //simpleByDepartment();
        simplelist();
        //departmentList();
    }

    /**
     * 获取部门id列表
     * @throws WxErrorException
     */
    public static void simplelist() throws WxErrorException {
        WxCpTpServiceImpl wxCpTpService = new WxCpTpServiceImpl();


        WxCpTpDefaultConfigImpl wxCpTpDefaultConfig=new WxCpTpDefaultConfigImpl();
        wxCpTpDefaultConfig.setSuiteId(corpid);
        wxCpTpDefaultConfig.setSuiteSecret(providerSecret);
        wxCpTpDefaultConfig.setSuiteTicket("suiteTicket");
        wxCpTpService.setWxCpTpConfigStorage(wxCpTpDefaultConfig);


        List<WxCpTpDepart> list = wxCpTpService.getWxCpTpDepartmentService().list(null);
        list.forEach(System.out::println);

    }
    /**
     * 获取部门id列表
     * @throws WxErrorException
     */
    public static void test() throws WxErrorException {
        WxCpTpServiceImpl wxCpTpService = new WxCpTpServiceImpl();


        WxCpTpDefaultConfigImpl wxCpTpDefaultConfig=new WxCpTpDefaultConfigImpl();
        wxCpTpDefaultConfig.setSuiteId(corpid);
        wxCpTpDefaultConfig.setSuiteSecret(providerSecret);
        wxCpTpDefaultConfig.setSuiteTicket("suiteTicket");
        wxCpTpService.setWxCpTpConfigStorage(wxCpTpDefaultConfig);


        List<WxCpTpDepart> list = wxCpTpService.getWxCpTpDepartmentService().list(null);
        list.forEach(System.out::println);

    }

}
